package top.lingkang.potatoserver.controller;

import cn.hutool.core.bean.BeanUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import top.lingkang.config.FinalContextHolder;
import top.lingkang.potatoserver.constants.HttpConstants;
import top.lingkang.potatoserver.dto.ResponseResult;
import top.lingkang.potatoserver.entity.User;
import top.lingkang.potatoserver.service.UserService;
import top.lingkang.potatoserver.vo.UserInfoVo;

/**
 * @author lingkang
 * @date 2021/9/19 14:20
 * @description
 */
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    @GetMapping("")
    public ResponseResult get() {
        String id = FinalContextHolder.getId();
        User user = userService.getUserById(Integer.valueOf(id));
        UserInfoVo vo = new UserInfoVo();
        BeanUtil.copyProperties(user, vo);
        return new ResponseResult(HttpConstants.OK, vo);
    }
}
